import {queryAttr, queryGoodsTypeName,addAttr, modAttr, delAttr,queryAll} from '../services/goods';

export default {
    namespace: 'attributeEdit',

    state: {
        data: {
            list: [],
            pagination: {},
        },
        loading: true,
        record:{},
    },

    effects: {
        * add({payload, callback}, {call, put}) {
            yield put({
                type: 'changeLoading',
                payload: true,
            });
            const response = yield call(addAttr, payload);
            yield put({
                type: 'changeLoading',
                payload: false,
            });

            if (callback) callback(response);
        },
        * mod({payload, callback}, {call, put}) {
            yield put({
                type: 'changeLoading',
                payload: true,
            });
            const response = yield call(modAttr, payload);
            yield put({
                type: 'changeLoading',
                payload: false,
            });

            if (callback) callback(response);
        },
        *queryGoodsType({payload,callback},{call,put}){
            const response=yield call(queryGoodsTypeName,payload);
            if(callback)callback(response);
        }
    },

    reducers: {
        changeLoading(state, action) {
            return {
                ...state,
                loading: action.payload,
            };
        },
    },
};

